
// pages/operation/operation.js
const urls = require('../../utils/url.js').urls
const http = require('../../utils/url.js').http
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isbl:0,
    items: [],
    nc: '',
    tx: '',
    types: 0,
    isws:0
  },
  userinfo: function(event) {
    wx.navigateTo({
      url: '../operation/operation_me/operation_me',
    })
  },
  detail: function(event) {
    var index = event.currentTarget.dataset.index;

    wx.setStorageSync('ywgdid', this.data.items[index].id)
    wx.setStorageSync('ywgdzt', this.data.items[index].gd_state)
    console.log(wx.getStorageSync('ywgdzt'))
    wx.navigateTo({
      url: '../operation/operation_work_detail/operation_work_detail',
    })
  },
  bt_jj: function(event) {
    var index = event.currentTarget.dataset.index;

    wx.setStorageSync('ywgdid', this.data.items[index].id)
    wx.setStorageSync('ywgdzt', this.data.items[index].gd_state)
    console.log(wx.getStorageSync('ywgdzt'))
    wx.navigateTo({
      url: '../operation/reject/reject',
    })
   
  },
  bt_wc: function (event) {
    var index = event.currentTarget.dataset.index;

    wx.setStorageSync('ywgdid', this.data.items[index].id)
    wx.setStorageSync('ywgdzt', this.data.items[index].gd_state)
    console.log(wx.getStorageSync('ywgdzt'))
    wx.navigateTo({
      url: '../operation/fault/fault',
    })
  },
  bt_sl: function(event) {
    var that = this
    var index = event.currentTarget.dataset.index;

    wx.setStorageSync('ywgdid', this.data.items[index].id)
    var param = {
      id: wx.getStorageSync("ywgdid")
    }

    http(urls.ywsl, param, function(res) {
      console.log(res)
      if (res.code == 0) {
        wx.showToast({
          title: res.msg,
        })

        if (getCurrentPages().length != 0) {
          //刷新当前页面的数据
          getCurrentPages()[getCurrentPages().length - 1].onLoad()
        }
      
   }

    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {


    wx.showNavigationBarLoading();
    var that = this;
    var param = {
      openid: app.globalData.openid //openId

    };
    http(urls.ywsy, param, function(res) {
      console.log(res)
      that.setData({
        items: res.data
      })
      console.log("???"+that.data.items)
      if (that.data.items == [] || that.data.items == null || that.data.items == ""){
        that.setData({
          isbl:0
        })
      }else{
        that.setData({
          isbl: 1
        }) 
      }
      wx.hideNavigationBarLoading();
    })

    var param = {
      openid: app.globalData.openid //openId

    };
    http(urls.details, param, function(res) {
      console.log(res)
      that.setData({
        nc: res.data.nickname,
        tx: res.data.avatarurl,
        isws:res.data.isws
      })
      console.log("是否完善:" + that.data.isws)
      if (that.data.isws != 1) {
        wx.showModal({
          title: '提示',
          content: '信息不完善,请尽快联系管理员完善信息',
          success: function (res) {
            if (res.confirm) {
              console.log('用户点击确定')
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })

      }
      wx.hideNavigationBarLoading();
    })

   

  },



  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
   
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    if (getCurrentPages().length != 0) {
      //刷新当前页面的数据
      getCurrentPages()[getCurrentPages().length - 1].onLoad()
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})